var e = require;
var t = module;
var n = exports;
var o,
    i =
        (this && this.__extends) ||
        ((o = function (e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function (e, t) {
            function n() {
                this.constructor = e;
            }
            o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
        }),
    r =
        (this && this.__decorate) ||
        function (e, t, n, o) {
            var i,
                r = arguments.length,
                a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
            else
                for (var s = e.length - 1; 0 <= s; s--)
                    (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
            return 3 < r && a && Object.defineProperty(t, n, a), a;
        },
    a =
        (this && this.__awaiter) ||
        function (e, a, s, c) {
            return new (s = s || Promise)(function (n, t) {
                function o(e) {
                    try {
                        r(c.next(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function i(e) {
                    try {
                        r(c.throw(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function r(e) {
                    var t;
                    e.done
                        ? n(e.value)
                        : ((t = e.value) instanceof s
                              ? t
                              : new s(function (e) {
                                    e(t);
                                })
                          ).then(o, i);
                }
                r((c = c.apply(e, a || [])).next());
            });
        },
    s =
        (this && this.__generator) ||
        function (n, o) {
            var i,
                r,
                a,
                s = {
                    label: 0,
                    sent: function () {
                        if (1 & a[0]) throw a[1];
                        return a[1];
                    },
                    trys: [],
                    ops: []
                },
                e = {next: t(0), throw: t(1), return: t(2)};
            return (
                "function" == typeof Symbol &&
                    (e[Symbol.iterator] = function () {
                        return this;
                    }),
                e
            );
            function t(t) {
                return function (e) {
                    return (function (t) {
                        if (i) throw new TypeError("Generator is already executing.");
                        for (; s; )
                            try {
                                if (
                                    (1,
                                    (i = 1),
                                    r &&
                                        (a =
                                            2 & t[0]
                                                ? r.return
                                                : t[0]
                                                ? r.throw || ((a = r.return) && a.call(r), 0)
                                                : r.next) &&
                                        !(a = a.call(r, t[1])).done)
                                )
                                    return a;
                                switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                    case 0:
                                    case 1:
                                        a = t;
                                        break;
                                    case 4:
                                        return s.label++, {value: t[1], done: !1};
                                    case 5:
                                        s.label++, (r = t[1]), (t = [0]);
                                        continue;
                                    case 7:
                                        (t = s.ops.pop()), s.trys.pop();
                                        continue;
                                    default:
                                        if (
                                            !(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                            (6 === t[0] || 2 === t[0])
                                        ) {
                                            s = 0;
                                            continue;
                                        }
                                        if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                            s.label = t[1];
                                            break;
                                        }
                                        if (6 === t[0] && s.label < a[1]) {
                                            (s.label = a[1]), (a = t);
                                            break;
                                        }
                                        if (a && s.label < a[2]) {
                                            (s.label = a[2]), s.ops.push(t);
                                            break;
                                        }
                                        a[2] && s.ops.pop(), s.trys.pop();
                                        continue;
                                }
                                t = o.call(n, s);
                            } catch (e) {
                                (t = [6, e]), (r = 0);
                            } finally {
                                i = a = 0;
                            }
                        if (5 & t[0]) throw t[1];
                        return {value: t[0] ? t[1] : void 0, done: !0};
                    })([t, e]);
                };
            }
        };
Object.defineProperty(n, "__esModule", {value: !0});
var c,
    l = e("index"),
    u = e("env"),
    p = e("events"),
    h = e("platform-const"),
    d = e("user-data"),
    f = e("vibrate"),
    m = e("cell-manager"),
    y = e("panel-manager"),
    g = e("player-info"),
    v = e("player-theme"),
    b = e("war-time"),
    _ = e("game-progress"),
    w = e("target-node"),
    t = cc._decorator,
    e = t.ccclass,
    t = t.property,
    e =
        ((c = cc.Component),
        i(C, c),
        (C.prototype.start = function () {
            (this.varsionLabel.string = "v" + u.env.version),
                (this.idLabel.string = "ID:" + d.userData.getUid()),
                (this.promptNode.active = g.playerInfo.getShowPromp()),
                (this.shareBtn.active = !1),
                (this.warNeedHideNode.active = g.playerInfo.getGameType() === g.gameType.nomal),
                (this.warTime.node.active = g.playerInfo.getGameType() === g.gameType.war),
                (this.addDeskBtn.active =
                    g.playerInfo.getGameType() === g.gameType.nomal && l.platform.string() != h.PlatformCode.Wechat),
                a(this, void 0, void 0, function () {
                    var t;
                    return s(this, function (e) {
                        switch ((0, e.label)) {
                            case 0:
                                return (
                                    e.trys.push([0, 5, , 6]),
                                    g.playerInfo.getGameType() !== g.gameType.nomal
                                        ? [3, 2]
                                        : [
                                              4,
                                              Promise.all([
                                                  this.loadTargetNode(),
                                                  this.loadGameProgress(),
                                                  this.cellManager.loadCellLayer()
                                              ])
                                          ]
                                );
                            case 1:
                                return e.sent(), this.setTargetNumber(!0), [3, 4];
                            case 2:
                                return [4, Promise.all([this.cellManager.loadWarCellLayer()])];
                            case 3:
                                e.sent(), (e.label = 4);
                            case 4:
                                return l.platform.startVideoRecord(), [3, 6];
                            case 5:
                                return (t = e.sent()), console.log("loading item error:", t), [3, 6];
                            case 6:
                                return [2];
                        }
                    });
                }),
                p.operEvent.on(this.onOperTap.bind(this));
        }),
        (C.prototype.onOperTap = function (e) {
            var t = this;
            null != e &&
                null != e.action &&
                (p.default.unlocknNumber == e.action && null != e.data
                    ? (this.setTargetLabel(!1), this.showShareBtn())
                    : p.default.nextLevel == e.action &&
                      null != e.data &&
                      (this.progress && (this.progress.reseatItem(), this.setTargetNumber(!1)),
                      l.platform.trackEvent("nextLevel", {level: g.playerInfo.getLevel()}),
                      this.showShareBtn()),
                p.default.unlocknLast == e.action && null != e.data
                    ? this.progress &&
                      this.progress.lastTarget(function () {
                          p.operEvent.emit({action: p.default.cloneCellLayer, data: {}});
                      })
                    : p.default.targetAnim == e.action
                    ? null != e.data &&
                      null != e.data.delayTime &&
                      this.scheduleOnce(function () {
                          t.target && t.target.playAnim();
                      }, e.data.delayTime)
                    : p.default.restartWarTime === e.action
                    ? this.warTime.reset()
                    : p.default.startWarTime === e.action
                    ? this.warTime.timeStart()
                    : p.default.saveWarTime === e.action && this.warTime.saveTime());
        }),
        (C.prototype.showShareBtn = function () {
            var e = this;
            this.scheduleOnce(function () {
                l.platform.stopVideoRecord(),
                    e.scheduleOnce(function () {
                        e.setShareBtn(!0);
                    }, 1);
            }, 2);
        }),
        (C.prototype.loadGameProgress = function () {
            return a(this, void 0, void 0, function () {
                var t;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return (
                                (t = v.playerTheme.getCurThemeName()),
                                [4, l.ResUtil.loadPrefab("prefab/prefab/" + t + "/game-progress")]
                            );
                        case 1:
                            return (
                                (t = e.sent()),
                                ((t = cc.instantiate(t)).parent = this.progressNode),
                                t.setPosition(0, 0),
                                (this.progress = t.getComponent(_.default)),
                                [2]
                            );
                    }
                });
            });
        }),
        (C.prototype.loadTargetNode = function () {
            return a(this, void 0, void 0, function () {
                var t;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return (
                                (t = v.playerTheme.getCurThemeName()),
                                [4, l.ResUtil.loadPrefab("prefab/prefab/" + t + "/target-node")]
                            );
                        case 1:
                            return (
                                (t = e.sent()),
                                ((t = cc.instantiate(t)).parent = this.progressNode),
                                t.setPosition(0, 0),
                                (this.target = t.getComponent(w.default)),
                                [2]
                            );
                    }
                });
            });
        }),
        (C.prototype.setShareBtn = function (e) {
            var t = this;
            this.shareBtn &&
                l.platform.string() == h.PlatformCode.Bytedance &&
                (this.unscheduleAllCallbacks(), (this.shareBtn.active = e)) &&
                ((e = new Date()),
                (this.showShareBtnTime = e.getTime()),
                this.scheduleOnce(function () {
                    l.platform.startVideoRecord(), t.setShareBtn(!1);
                }, this.delayHideShareBtnTime));
        }),
        (C.prototype.setTargetNumber = function (e) {
            this.targetNumbers = g.playerInfo.getTargetNumbers();
            var t = this.progress.getTargetItemLength();
            this.targetNumbers.length === t
                ? (this.progress.setTargetNumbers(this.targetNumbers), this.setTargetLabel(e))
                : console.log("length error:", this.targetNumbers.length, t);
        }),
        (C.prototype.setTargetLabel = function (e) {
            var n, o;
            null != this.targetNumbers
                ? ((o = n = 0),
                  g.playerInfo.getCurTargetNumber(function (e, t) {
                      (n = e), (o = t);
                  }),
                  this.target && (this.target.loadTargetLabel(n), this.target.loadTargetLabelBg(n)),
                  this.progress.setCurTargetNumber(o, e))
                : console.log("this.targetNumber.error..", this.targetNumbers);
        }),
        (C.prototype.onAddDesk = function () {
            l.platform.addShortcut();
        }),
        (C.prototype.onShare = function () {
            var e = new Date(),
                t = Math.floor(0.001 * (e.getTime() - this.showShareBtnTime)),
                n = g.playerInfo.getLevel(),
                e = g.playerInfo.getGameType() === g.gameType.nomal ? "main" : "challenge";
            l.platform.shareVideoRecord(n, t.toString(), "coin sort", e);
        }),
        (C.prototype.onSettingBtnTap = function () {
            f.vibrate.play(f.VibrateNewType.SHORT),
                y.PanelManager.ins.open("prefab/panel/settingPanel", null),
                this.warTime.timePause();
        }),
        (C.prototype.getWarTimes = function () {
            return this.warTime.getWarTimes();
        }),
        (C.prototype.setPromptNodeActive = function () {
            this.promptNode.active = g.playerInfo.getShowPromp();
        }),
        r([t(cc.Node)], C.prototype, "shareBtn", void 0),
        r([t(cc.Node)], C.prototype, "addDeskBtn", void 0),
        r([t(cc.Node)], C.prototype, "progressNode", void 0),
        r([t(m.default)], C.prototype, "cellManager", void 0),
        r([t(cc.Node)], C.prototype, "targetNode", void 0),
        r([t(cc.Node)], C.prototype, "warNeedHideNode", void 0),
        r([t(b.default)], C.prototype, "warTime", void 0),
        r([t(cc.Node)], C.prototype, "promptNode", void 0),
        r([t(cc.Label)], C.prototype, "varsionLabel", void 0),
        r([t(cc.Label)], C.prototype, "idLabel", void 0),
        r([e], C));
function C() {
    var e = (null !== c && c.apply(this, arguments)) || this;
    return (
        (e.shareBtn = null),
        (e.addDeskBtn = null),
        (e.progressNode = null),
        (e.cellManager = null),
        (e.targetNode = null),
        (e.warNeedHideNode = null),
        (e.warTime = null),
        (e.promptNode = null),
        (e.varsionLabel = null),
        (e.idLabel = null),
        (e.targetNumbers = null),
        (e.delayHideShareBtnTime = 10),
        (e.showShareBtnTime = 0),
        (e.progress = null),
        (e.target = null),
        e
    );
}
n.default = e;
